/*	
 *  Copyright (c) 2009-@year@. The GUITAR group at the University of Maryland. Names of owners of this group may
 *  be obtained by sending an e-mail to atif@cs.umd.edu
 * 
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 *  documentation files (the "Software"), to deal in the Software without restriction, including without 
 *  limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 *	the Software, and to permit persons to whom the Software is furnished to do so, subject to the following 
 *	conditions:
 * 
 *	The above copyright notice and this permission notice shall be included in all copies or substantial 
 *	portions of the Software.
 *
 *	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
 *	LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 
 *	EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
 *	IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 
 *	THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 */
package edu.umd.cs.emut.model.wapper;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;

import edu.umd.cs.emut.model.xml.AttributesType;
import edu.umd.cs.emut.model.xml.ComponentType;
import edu.umd.cs.emut.model.xml.PropertyType;

/**
 * 
 * @author <a href="mailto:baonn@cs.umd.edu"> Bao N. Nguyen </a>
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ComponentType", propOrder = { "componentID", "attributes" })
public class ComponentTypeWrapper extends ComponentType {

	/**
	 * 
	 */
	public ComponentTypeWrapper(ComponentType component) {
		super();
		this.attributes = component.getAttributes();
		this.componentID = component.getComponentID();
	}

	/**
	 * Get a list of property by name
	 * 
	 * @param name
	 * @return list of property values <code>null</code> if there is not such
	 *         property
	 */
	public List<String> getValueListByName(String name) {
		AttributesType attributes = this.getAttributes();
		if (attributes == null)
			return null;

		List<PropertyType> lProperty = attributes.getProperty();

		for (PropertyType p : lProperty) {
			if (p.getName().equals(name)) {
				return p.getValue();
			}
		}

		return null;
	}

	/**
	 * Find first property value by name
	 * 
	 * <p>
	 * 
	 * @param name
	 * @return the attribute value
	 */
	public String getFirstValueByName(String name) {

		List<String> values = getValueListByName(name);
		if (values == null)
			return null;
		if (values.size() < 1)
			return null;

		return values.get(0);
	}
}
